package com.guorui.utils;

import java.util.List;

/*
    原来是：先setAttibute（如request.setAttribute("findall",findall);），在在需要的地方get
    现在：先set入PageUtils中(如pageUtils.setDataList)，之后setAttibute一个PageUtils对象
    也就是说现在只需要在servlet中set当前页，总条数，结果集就行
 */

//分页工具类(所以只与show2有关)
public class PageUtils<T> {
    //5个属性
    private int pageIndex;      //页码(当前页)
    private int pageSize = DateUtils.PAGESIZE;       //每页显示条数
    private int totalCount;     //总条数
    private int totalPages;     //总页数
    //写什么类型都不安全，写T比较合适
    private List<T> dataList;   //查询的结果数据

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPages() {
        return totalCount% pageSize == 0?totalCount/pageSize:totalCount/pageSize+1;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public PageUtils() {
    }

    public PageUtils(int pageIndex, int pageSize, int totalCount, int totalPages, List<T> dataList) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPages = totalPages;
        this.dataList = dataList;
    }
}
